//
//  LeisureTitle.m
//  庐山通
//
//  Created by zcj on 15-10-23.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "LeisureTitle.h"
#import "Grouble.h"

@interface LeisureTitle()
@property (nonatomic,weak)UIButton * jinxuan;
@property (nonatomic,weak)UIButton * faxian;
@property (nonatomic,weak)UIButton * zhuanti;
@property (nonatomic,weak)UIButton * threeBtn;

@end
@implementation LeisureTitle

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIButton * jinxuan = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        jinxuan.titleLabel.font = [UIFont systemFontOfSize:15];
        [self AddButton:@"发现" btn:jinxuan];
        [self addSubview:jinxuan];// 第一个添加进去d的
        
        UIButton * faxian = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        faxian.titleLabel.font = [UIFont systemFontOfSize:15];
        [self AddButton:@"精选" btn:faxian];
        [self addSubview:faxian];
        
        UIButton * zhuanti = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        zhuanti.titleLabel.font = [UIFont systemFontOfSize:15];
        [self AddButton:@"专场" btn:zhuanti];
        [self addSubview:zhuanti];
        
        // Initialization code
    }
    return self;
}
- (void)AddButton:(NSString *)title btn:(UIButton *)allBtn
{
    [allBtn setTitle:title forState:UIControlStateNormal];
    [allBtn setTitleColor:ZCJColor(75, 75, 75) forState:UIControlStateNormal];
    [allBtn setTitleColor:ZCJColor(247, 133, 136) forState:UIControlStateSelected];
    //allBtn.tintColor = ZCJColor(247, 133, 136);
    [allBtn addTarget:self action:@selector(btnWithClick:) forControlEvents:UIControlEventTouchUpInside];
    
}
// 通知控制器该切换了
- (void)btnWithClick:(UIButton *)btn
{
    if ([self.delegate respondsToSelector:@selector(LeisureTitleClick:scroolIndex:)]) {
        
        [self.delegate LeisureTitleClick:self scroolIndex:btn.tag];
    }
    self.threeBtn.selected = NO;
    self.threeBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    self.threeBtn.backgroundColor = [UIColor clearColor];
    
    btn.selected = YES;
    btn.titleLabel.font = [UIFont systemFontOfSize:20];
    self.threeBtn = btn;
}
// 滚动了视图
- (void)titleChange:(NSInteger)index
{
    self.threeBtn.selected = NO;
    self.threeBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    self.threeBtn.backgroundColor = [UIColor clearColor];
    UIButton * selectBtn = self.subviews[index];
    selectBtn.selected = YES;
    selectBtn.titleLabel.font = [UIFont systemFontOfSize:20];
    self.threeBtn = selectBtn;
    
}

-(void)layoutSubviews
{
    CGFloat btnY=0;
    int count=(int)self.subviews.count;
    CGFloat btnX=0;
    CGFloat btnW=self.width/count;
    CGFloat btnH=self.height;
    for(int i=0;i<count;i++){
        btnX=btnW*i;
        UIButton *btn=self.subviews[i];
        btn.tag=i;
        btn.frame=CGRectMake(btnX, btnY, btnW, btnH);
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
